package dang.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class DigestUtil {
	public static String md5(String str){
		try {
			//将str采用md5加密
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] bs = md.digest(str.getBytes());
			//将加密后的byte[]数组使用base64算法表示
			BASE64Encoder encoder = new BASE64Encoder();
			return encoder.encode(bs);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return "";
		}
	}
	
	public static void main(String[] args){
		System.out.println(md5("123"));
		System.out.println(md5("adfasdfadsfadsf"));
		System.out.println(md5("324324323242"));
	}
	
}
